﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;

using mvcForum.Web.Areas.ForumAdmin.ViewModels;

namespace mvcForum.Web.Areas.ForumAdmin.Helpers {

	public static class BreadcrumbHelper {

		public static List<BreadcrumbNode> BuildPath(Core.Group group, UrlHelper url) {
			List<BreadcrumbNode> output = new List<BreadcrumbNode>();
			// TODO: Text!!
			output.Add(new BreadcrumbNode { Title = "Groups", Action = url.Action("index", "group", new { area = "forumadmin" }) });
			output.Add(new BreadcrumbNode { Title = group.Name, Action = url.Action("update", "group", new { id = group.Id, area = "forumadmin" }) });

			return output;
		}

		public static List<BreadcrumbNode> BuildPath(Core.ForumUser user, UrlHelper url) {
			List<BreadcrumbNode> output = new List<BreadcrumbNode>();
			// TODO: Text!!
			output.Add(new BreadcrumbNode { Title = "Users", Action = url.Action("index", "user", new { area = "forumadmin" }) });
			output.Add(new BreadcrumbNode { Title = user.Name, Action = url.Action("update", "user", new { id = user.Id, area = "forumadmin" }) });

			return output;
		}

		public static List<BreadcrumbNode> BuildPath(Core.Board board, UrlHelper url) {
			List<BreadcrumbNode> output = new List<BreadcrumbNode>();
			// TODO: Text!!
			output.Add(new BreadcrumbNode { Title = "Home", Action = url.Action("index", "home", new { area = "forumadmin" }) });
			output.Add(new BreadcrumbNode { Title = board.Name, Action = url.Action("update", "board", new { id = board.Id, area = "forumadmin" }) });

			return output;
		}

		public static List<BreadcrumbNode> BuildPath(Core.AccessMask mask, UrlHelper url) {
			List<BreadcrumbNode> output = BuildPath(mask.Board, url);
			output.Add(new BreadcrumbNode { Title = mask.Name, Action = url.Action("update", "accessmask", new { id = mask.Id, area = "forumadmin" }) });

			return output;
		}

		public static List<BreadcrumbNode> BuildPath(Core.Category category, UrlHelper url) {
			List<BreadcrumbNode> output = BuildPath(category.Board, url);
			output.Add(new BreadcrumbNode { Title = category.Name, Action = url.Action("update", "category", new { id = category.Id }) });

			return output;
		}

		public static List<BreadcrumbNode> BuildPath(Core.Forum forum, UrlHelper url) {
			List<BreadcrumbNode> output;
			if (forum.ParentForum != null) {
				output = BuildPath(forum.ParentForum, url);
			}
			else {
				output = BuildPath(forum.Category, url);
			}
			output.Add(new BreadcrumbNode { Title = forum.Name, Action = url.Action("update", "forum", new { id = forum.Id }) });

			return output;
		}
	}
}